[contents] [prev] [next] [top] [bottom] (7 out of 12)

Definition of Classes

The class definition expression creates a new class, which inherits the properties and behavior of a list of superclasses. Each item in the list of superclasses must be a simple expression that returns a class. The class name, which is required, must be a symbol. If this symbol is specified in the object definition expression, it is declared as a constant, and can no longer be assigned to another object.

classDefExpr	::=	class symbol ( supersList ) classBody end 
supersList	::=	simpleExpr [ , supersList ]* 

The body of a class definition expression has four clauses. These clauses are used to define class variables, class methods, instance variables, and instance methods. All four clauses are optional, but those that are present must be supplied in the specified order.

classBody	::=	[ classVars ] [ instanceVars ] [ classMethods ] [ instMethods ] 

Class and instance variables are defined in separate clauses within the body of the class definition expression. Class and instance variables are implemented through accessor methods, which get or set a value. Virtual instance variables, which do not correspond with any physical slot, are implemented as methods. Real instance variables, although they are associated with an actual slot in the memory, are also queried through getter and setter methods. You use the class and object definition expressions to define real variables.

classVars	::=	class var[iable]s varList 
instanceVars	::=	inst[ance] var[iable]s varList 
varList	::=	[ qualifiers ] variable moreVars 
moreVars	::=	[ endOfLine ]+ varList 
	|	[ , varList ]* 

When a real class or instance variable is defined, you can specify whether that variable is readonly, transient, or reference. These options, if specified, must be given in order. A variable that is read-only can be retrieved from the object store, but not changed. A variable that is transient cannot be stored in the object store, so its value is discarded each time the object is saved and retrieved. If a variable is transient, you can specify an optional initialization function to restore its value each time the class or object is retrieved. A reference variable is a real variable that is not loaded from the object store until it is actually needed by the system.

qualifiers	::=	[ readonly ] [ transientOption ] [ reference ] 
transientOption	::=	transient [ initializer factor ] 

Class and instance methods can be defined within the body of a class definition expression. Each method definition must begin on a new line.

classMethods	::=	class methods methods 
instMethods	::=	inst[ance] methods methods 
methods	::=	methodDefExpr moreMethods 
moreMethods	::=	[ endOfLine ]* methods 

Note that both class and instance methods can be defined outside the class body, as free methods. Discussion of method definition expressions, and of syntax for free methods, begins on page 247.


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.